package com.deliveryservicesystem.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * File Name: Supplier.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "SUPPLIER")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Supplier.findAll", query = "SELECT s FROM Supplier s"),
    @NamedQuery(name = "Supplier.findBySupplierNo", query = "SELECT s FROM Supplier s WHERE s.supplierNo = :supplierNo"),
    @NamedQuery(name = "Supplier.findBySupplierName", query = "SELECT s FROM Supplier s WHERE s.supplierName = :supplierName"),
    @NamedQuery(name = "Supplier.findByContactNo", query = "SELECT s FROM Supplier s WHERE s.contactNo = :contactNo"),
    @NamedQuery(name = "Supplier.findByAddress", query = "SELECT s FROM Supplier s WHERE s.address = :address")
})
public class Supplier implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_SUPPLIER_NO", sequenceName = "SEQ_SUPPLIER_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_SUPPLIER_NO")
    @Basic(optional = false)
    @Column(name = "SUPPLIER_NO")
    private Integer supplierNo;
    @Basic(optional = false)
    @Column(name = "SUPPLIER_NAME")
    private String supplierName;
    @Basic(optional = false)
    @Column(name = "CONTACT_NO")
    private String contactNo;
    @Basic(optional = false)
    @Column(name = "ADDRESS")
    private String address;
    @OneToMany(mappedBy = "supplierNo")
    private List<Product> productList;

    public Supplier()
    {
    }

    public Supplier(Integer supplierNo)
    {
        this.supplierNo = supplierNo;
    }

    public Supplier(Integer supplierNo, String supplierName, String contactNo, String address)
    {
        this.supplierNo = supplierNo;
        this.supplierName = supplierName;
        this.contactNo = contactNo;
        this.address = address;
    }

    public Integer getSupplierNo()
    {
        return supplierNo;
    }

    public void setSupplierNo(Integer supplierNo)
    {
        this.supplierNo = supplierNo;
    }

    public String getSupplierName()
    {
        return supplierName;
    }

    public void setSupplierName(String supplierName)
    {
        this.supplierName = supplierName;
    }

    public String getContactNo()
    {
        return contactNo;
    }

    public void setContactNo(String contactNo)
    {
        this.contactNo = contactNo;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    @XmlTransient
    public List<Product> getProductList()
    {
        return productList;
    }

    public void setProductList(List<Product> productList)
    {
        this.productList = productList;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (supplierNo != null ? supplierNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Supplier))
        {
            return false;
        }
        Supplier other = (Supplier) object;
        if ((this.supplierNo == null && other.supplierNo != null) || (this.supplierNo != null && !this.supplierNo.equals(other.supplierNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Supplier Number: " + supplierNo
                + "\nSupplier Name: " + supplierName
                + "\nContact Number: " + contactNo
                + "\nAddress: " + address;
    }
}
